package com.AAL.DAO;

import java.util.List;

import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.IProcessingPlanOfPlanDAO;
import com.AAL.Model.LogForPlan;
import com.AAL.Model.ProcessingPlanOfPlan;
import com.AAL.Utils.HibernateUtil;

public class ProcessingPlanOfPlanDAO implements IProcessingPlanOfPlanDAO {

	@Override
	public ProcessingPlanOfPlan saveAndUpdateProcessingPlanOfPlan(
			ProcessingPlanOfPlan processingPlanOfPlan) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		try {
			session.saveOrUpdate(processingPlanOfPlan);
		} catch (Exception e) {
			return null;
		}
		session.getTransaction().commit();
		return processingPlanOfPlan;
	}

	@Override
	public ProcessingPlanOfPlan deleteProcessingPlanOfPlan(
			int processingPlanOfPlanID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		try {
			session.beginTransaction();
			ProcessingPlanOfPlan processingPlanOfPlan = (ProcessingPlanOfPlan) session
					.load(ProcessingPlanOfPlan.class, processingPlanOfPlanID);
			if (null != processingPlanOfPlan) {
				session.delete(processingPlanOfPlan);
			}
			session.getTransaction().commit();
			return processingPlanOfPlan;
		} catch (Exception e) {
			e.printStackTrace();
			session.getTransaction().rollback();
			return null;
		}
	}

	@Override
	public ProcessingPlanOfPlan getProcessingPlanOfPlan(
			int processingPlanOfPlanID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		ProcessingPlanOfPlan processingPlanOfPlan = (ProcessingPlanOfPlan) session
				.load(ProcessingPlanOfPlan.class, processingPlanOfPlanID);
		return processingPlanOfPlan;
	}

	@Override
	public List<ProcessingPlanOfPlan> getLstProcessingPlanOfPlansByLogForPlan(
			LogForPlan logForPlan) {
		// TODO Auto-generated method stub
		return null;
	}

}
